package com.xw.controller.admin;

import com.xw.utils.ResultVOUtil;
import com.xw.vo.ResultVO;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

@RestController
@RequestMapping({"/sys"})
public class SysInfoController {

//    private final IUserService userService;
//    private final IArticleService articleService;
//    private final IEnterpriseService enterpriseService;
//    private final IPositionService positionService;
//
//    public SysInfoController(IUserService userService, IArticleService articleService, IEnterpriseService enterpriseService, IPositionService positionService) {
//        this.userService = userService;
//        this.articleService = articleService;
//        this.enterpriseService = enterpriseService;
//        this.positionService = positionService;
//    }


    @GetMapping("/findInfo")
    public ResultVO<?> findInfo() throws UnknownHostException {
        Map<String, Object> m = new HashMap<>();
        Runtime r = Runtime.getRuntime();
        Properties props = System.getProperties();
        InetAddress addr;
        addr = InetAddress.getLocalHost();
        String ip = addr.getHostAddress();
        Map<String, String> map = System.getenv();
//        String userName = map.get("USERNAME");// 获取用户名
//        String computerName = map.get("COMPUTERNAME");// 获取计算机名
//        m.put("userName", userName);
//        m.put("computerName", computerName);
        m.put("ip", ip);
        m.put("totalMemory", String.valueOf(r.totalMemory()));
        m.put("freeMemory", String.valueOf(r.freeMemory()));
        m.put("javaVersion", props.getProperty("java.specification.version"));
        m.put("osName", props.getProperty("os.name"));
        m.put("osArch", props.getProperty("os.arch"));
        m.put("osVersion", props.getProperty("os.version"));
        return ResultVOUtil.success(m);
    }


//    @GetMapping("/findDataStatistics")
//    public ResultVO<?> findDataStatistics() {
//        Map<String, Integer> map = new HashMap<>();
//        Integer userCount = userService.findUserCount();
//        Integer checkUserCount = userService.findCheckUserCount();
//        Integer enterpriseCount = enterpriseService.findEnterpriseCount();
//        Integer checkEnterpriseCount = enterpriseService.findCheckEnterpriseCount();
//        Integer positionCount = positionService.findPositionCount();
//        Integer checkPositionCount = positionService.checkPositionCount();
//        Integer articleCount = articleService.findArticleCount();
//        map.put("userCount", userCount == null ? 0 : userCount);
//        map.put("checkUserCount", checkUserCount == null ? 0 : checkUserCount);
//        map.put("enterpriseCount", enterpriseCount == null ? 0 : enterpriseCount);
//        map.put("checkEnterpriseCount", checkEnterpriseCount == null ? 0 : checkEnterpriseCount);
//        map.put("positionCount", positionCount == null ? 0 : positionCount);
//        map.put("checkPositionCount", checkPositionCount == null ? 0 : checkPositionCount);
//        map.put("articleCount", articleCount == null ? 0 : articleCount);
//        return ResultVOUtil.success(map);
//    }

}
